﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Security.Cryptography;

public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (!this.check_T.Text.Equals(Session["num"].ToString()))
            Response.Redirect("~/login.aspx");
        check();
    }

    private void check()
    {
        string username = this.c_username.Text;
        string password = this.c_password.Text;
        string[] userinfo = new string[4];
        MD5 md5 = new MD5CryptoServiceProvider();
        SqlConnection conn = DataBase.getConnection();

        管理员信息表dao ad_dao = new 管理员信息表dao();

        管理员信息表 ad = ad_dao.GetModel(username);

        if (ad != null)
        {
            password += ad.seed;
            byte[] b = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));
            string temp = "";
            for (int i = 0; i < b.Length; i++)
            {
                temp += b[i].ToString("X");
            }
            if (temp.Equals(ad.password))
            {

                Session.Add("userinfo", ad);
                Response.Redirect("default.htm");
            }
            else
            {
                Session.Remove("userinfo");
                Response.Redirect("login.aspx");

            }

        }
        else
        {
            Session.Remove("userinfo");

        }

        if (Session["userinfo"] != null && Session["userinfo"].ToString().Trim() != "")
        {
            Response.Redirect("default.htm");
        }
        else
        {
            Response.Redirect("login.aspx");
        }

    }
}
